import { defineStore } from "pinia";
import { ref } from "vue";
import { tagIconList } from '@renderer/composables/iconUtils'

export const useConfigStore = defineStore('config', () => {
  const config = ref({
    color: '#adff2f',
    opacity: 0.6,
    max: 10,
    step: 1,
    autoOpen: false, // 是否开启自启动
    backgroundColorType: 2, // 背景颜色类型 0 深色，1 浅色，2 无色
    tagIconId: 'waterDrop'
  })

  const getStepStr = () => {
    return config.value.step > 0 ? `+${config.value.step}` : config.value.step
  }

  const getTagIcon = () => {
    for (const icon of tagIconList) {
      if (icon.id === config.value.tagIconId) {
        return icon
      }
    }
    return tagIconList[0]
  }

  const getBackgroundColorByType = () => {
    if (config.value.backgroundColorType === 0) {
      return "#000"
    } else if (config.value.backgroundColorType === 1) {
      return "#fff"
    } else if (config.value.backgroundColorType === 2) {
      return "transparent"
    }
    return "transparent"
  }

  return {
    config,
    getStepStr,
    getTagIcon,
    getBackgroundColorByType
  }
}, {
  persist: true
})
